﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RegExStudio.RegExStudioEventArgs;

namespace RegExStudio.CustomControls
{
    /// <summary>
    /// Erweitert die TabPage Klasse, so das direkt ein CtrlRegEx UserControl verwendet wird
    /// </summary>
    public partial class CtrlRegExTab : TabPage
    {
        /// <summary>
        /// Das UserControl zur RegEx Bearbeitung
        /// </summary>
        private UserControls.CtrlRegEx _ctrlRegEx;

        /// <summary>
        /// Die RegEx mit Optionen und Eingabe die verarbeitet wird
        /// </summary>
        public Xml.RegExSetRegEx RegEx
        {
            get { return _ctrlRegEx.RegEx; }
        }

        /// <summary>
        /// ctor
        /// Leitet die zu verwendende RegEx an das UserControl weiter
        /// </summary>
        /// <param name="regEx"></param>
        public CtrlRegExTab(Xml.RegExSetRegEx regEx)
        {
            InitializeComponent();

            _ctrlRegEx = new UserControls.CtrlRegEx(regEx);
            _ctrlRegEx.Dock = DockStyle.Fill;
            _ctrlRegEx.RegExChanged += new UserControls.CtrlRegEx.RegExChangedEventHandler(ctrlRegEx_RegExChanged);
            this.Text = regEx.Name;
            this.Controls.Add(_ctrlRegEx);
        }

        /// <summary>
        /// Event wenn die RegEx geändert wird
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ctrlRegEx_RegExChanged(object sender, RegExChangedEventArgs e)
        {
            this.Text = _ctrlRegEx.RegEx.Name;
            OnRegExChanged();
        }

        /// <summary>
        /// Eventhandler zum weiterleiten des RegExChanged events
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public delegate void RegExChangedEventHandler(object sender, RegExChangedEventArgs e);

        /// <summary>
        /// Event das gefeuert wird, wenn die RegEx geändert wurde
        /// </summary>
        public event RegExChangedEventHandler RegExChanged;
        
        /// <summary>
        /// Feuert das Event wenn die RegEx geändert wurde
        /// </summary>
        protected virtual void OnRegExChanged()
        {
            if (RegExChanged != null)
            {
                RegExChanged(this, new RegExChangedEventArgs(_ctrlRegEx.RegEx));
            }
        }

        /// <summary>
        /// Vergrößert die Schriftart im Input Control
        /// </summary>
        public void IncreaseFont()
        {
            _ctrlRegEx.IncreaseFont();
        }

        /// <summary>
        /// Verkleinert die Schriftart im Input Control
        /// </summary>
        public void DecreaseFont()
        {
            _ctrlRegEx.DecreaseFont();
        }
    }
}
